#include "dnf.h"
using namespace cdnf;
bool DNF::getValue(bool* valuation) {
	if (isDegenerated())
		return degeneratedValue;
	for (unsigned int i = 0; i < conjunctions.size(); i++) {
		if (conjunctions[i].getValue(valuation))
			return true;
	}
	return false;
}
bool DNF::getValue(Valuation& valuation) {
	if (isDegenerated())
		return degeneratedValue;
	for (unsigned int i = 0; i < conjunctions.size(); i++) {
		if (conjunctions[i].getValue(valuation))
			return true;
	}
	return false;
}
bool DNF::getValue(std::vector<int> values){
	if (isDegenerated())
		return degeneratedValue;
	for (unsigned int i = 0; i < conjunctions.size(); i++) {
		if (conjunctions[i].getValue(values))
			return true;
	}
	return false;
}
std::vector<Conjunction>& DNF::getConjunctions() {
	return this->conjunctions;
}
void DNF::addConjunction(Conjunction& c) {
	this->conjunctions.push_back(c);
}
Conjunction& DNF::getConjunction(int index) {
	return this->conjunctions.at(index);
}
void DNF::setConjunction(int index, Conjunction& c) {
	this->conjunctions[index] = c;
}
int DNF::size(){
	return this->conjunctions.size();
}
bool DNF::isDegenerated() {
	if (conjunctions.size() == 0) {
		degeneratedValue = false;
		return true;
	}
	for (unsigned int i = 0; i < conjunctions.size(); i++)
		if (conjunctions[i].isDegenerated()
				&& conjunctions[i].getDegeneratedValue()) {
			degeneratedValue = true;
			return true;
		}
	return false;
}
void DNF::setDegeneratedValue(bool degeneratedValue) {
	this->degeneratedValue = degeneratedValue;
}
bool DNF::getDegeneratedValue() {
	return this->degeneratedValue;
}
